home *** CD-ROM | disk | FTP | other *** search
-
- SEMCTL(2) UNIX Programmer's Manual SEMCTL(2)
-
- NNAAMMEE
- sseemmccttll - semaphore control operations
-
- SSYYNNOOPPSSIISS
- ##iinncclluuddee <<ssyyss//ttyyppeess..hh>>
- ##iinncclluuddee <<ssyyss//iippcc..hh>>
- ##iinncclluuddee <<ssyyss//sseemm..hh>>
-
- _i_n_t
- sseemmccttll(_i_n_t _s_e_m_i_d, _i_n_t _s_e_m_n_u_m, _i_n_t _c_m_d, _u_n_i_o_n _s_e_m_u_n _a_r_g)
-
- DDEESSCCRRIIPPTTIIOONN
- The sseemmccttll() system call provides a number of control operations on the
- semaphore specified by _s_e_m_n_u_m and _s_e_m_i_d. The operation to be performed is
- specified in _c_m_d (see below). _a_r_g is a union of the following fields:
-
- int val; /* value for SETVAL */
- struct semid_ds *buf; /* buffer for IPC_{STAT,SET} */
- u_short *array; /* array for GETALL & SETALL */
-
- The semid_ds structure used in the IPC_SET and IPC_STAT commands is de-
- fined as follows in <_s_y_s_/_s_e_m_._h>:
-
- struct semid_ds {
- struct ipc_perm sem_perm; /* operation permissions */
- struct sem *sem_base; /* semaphore set */
- u_short sem_nsems; /* number of sems in set */
- time_t sem_otime; /* last operation time */
- time_t sem_ctime; /* last change time */
- };
-
- The ipc_perm structure used inside the semid_ds structure is defined in
- <_s_y_s_/_i_p_c_._h> and looks like this:
-
- struct ipc_perm {
- ushort cuid; /* creator user id */
- ushort cgid; /* creator group id */
- ushort uid; /* user id */
- ushort gid; /* group id */
- ushort mode; /* r/w permission (see chmod(2)) */
- ushort seq; /* sequence # (to generate unique msg/sem/shm id) */
- key_t key; /* user specified msg/sem/shm key */
- };
-
- sseemmccttll() provides the following operations:
-
- GETVAL Return the value of the semaphore.
-
- SETVAL Set the value of the semaphore to _a_r_g_._v_a_l.
-
- GETPID Return the pid of the last process that did an operation on
- this semaphore.
-
- GETNCNT Return the number of processes waiting to acquire the
- semaphore.
-
- GETZCNT Return the number of processes waiting for the value of the
- semaphore to reach 0.
-
- GETALL Return the values for all the semaphores associated with
-
-
- _s_e_m_i_d.
-
- SETALL Set the values for all the semaphores that are associated with
- the semaphore identifier _s_e_m_i_d to the corresponding values in
- _a_r_g_._a_r_r_a_y.
-
- IPC_STAT Gather statistics about a semaphore and place the information
- in the semid_ds structure pointed to by _a_r_g_._b_u_f (see above).
-
- IPC_SET Set the value of the _s_e_m___p_e_r_m_._u_i_d, _s_e_m___p_e_r_m_._g_i_d and
- _s_e_m___p_e_r_m_._m_o_d_e fields in the structure associated with the
- semaphore. The values are taken from the corresponding fields
- in the structure pointed to by _a_r_g_._b_u_f. This operation can on-
- ly be executed by the super-user, or a process that has an ef-
- fective user id equal to either _s_e_m___p_e_r_m_._c_u_i_d or _s_e_m___p_e_r_m_._u_i_d
- in the data structure associated with the message queue.
-
- IPC_RMID Remove the semaphores associated with _s_e_m_i_d from the system
- and destroy the data structures associated with it. Only the
- super-user or a process with an effective uid equal to the
- _s_e_m___p_e_r_m_._c_u_i_d or _s_e_m___p_e_r_m_._u_i_d values in the data structure as-
- sociated with the semaphore can do this.
-
- The permission to read or change a message queue (see semop(2)) is de-
- termined by the _s_e_m___p_e_r_m_._m_o_d_e field in the same way as is done with files
- (see chmod(2)), but the effective uid can match either the _s_e_m___p_e_r_m_._c_u_i_d
- field or the _s_e_m___p_e_r_m_._u_i_d field, and the effective gid can match either
- _s_e_m___p_e_r_m_._c_g_i_d or _s_e_m___p_e_r_m_._g_i_d.
-
- RREETTUURRNN VVAALLUUEESS
- For the GETVAL, GETPID, GETNCNT and GETZCNT operations, sseemmccttll() returns
- one of the values described above if successful. All other operations
- will make sseemmccttll() return 0 if no errors occur. Otherwise -1 is returned
- and _e_r_r_n_o set to reflect the error.
-
- EERRRROORRSS
- sseemmccttll() will fail if:
-
- [EPERM] _c_m_d is equal to IPC_SET or IPC_RMID and the caller is not
- the super-user, nor does the effective uid match either the
- _s_e_m___p_e_r_m_._u_i_d or _s_e_m___p_e_r_m_._c_u_i_d fields of the data structure
- associated with the message queue.
-
- [EACCESS] The caller has no operation permission for this semaphore.
-
- [EINVAL] _s_e_m_i_d is not a valid message semaphore identifier.
-
- _c_m_d is not a valid command.
-
- [EFAULT] _a_r_g_._b_u_f specifies an invalid address.
-
- SSEEEE AALLSSOO
- semop(2) semget(2)
-
- NetBSD August 17, 1995 2
-